#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 510;

int ld,sz[N],tot,siz[N];
short f[N][N][N],col[N],tmp[N][N],dfn[N],ind[N],tim,n;
vector<pii> G[N];
int dis[N][N];

void dfs1(int x,int p){
	dfn[x] = ++tim; ind[tim] = x; sz[x] = 1;
	for(pii y : G[x]){
		if(y.fi == p) continue; dfs1(y.fi,x); sz[x] += sz[y.fi];
	}
}

void dfs2(int *d,int x,int p,int ddis = 0){
	d[x] = ddis;
	for(pii y : G[x]){if(y.fi == p) continue; dfs2(d,y.fi,x,min(ddis + y.se,ld+1));}
}

void dp(int x,int p){
	for(int i = 1;i <= n;i++) if(dis[x][i] <= ld && x != i) f[x][0][i] = 0;
	f[x][1][x] = col[x] ^ 1; siz[x] = 1;
	for(pii d : G[x]){
		int y = d.fi;
		if(y == p) continue; dp(y,x);
		for(int i = 0;i <= min(siz[x] + siz[y],tot);i++)
			for(int j = 1;j <= n;j++)
				tmp[i][j] = n + 1;
		for(int i = 0;i <= min(siz[x],tot);i++)
			for(int j = 0;j <= min(siz[y],tot);j++){
				short mn = n + 1;
				for(int l = dfn[y];l <= dfn[y] + sz[y] - 1;l++) mn = min(mn,f[y][j][ind[l]]);
				for(int l = 1;l <= n;l++){
					if(f[x][i][l] + f[y][j][l] < tmp[i+j][l]) tmp[i+j][l] = f[x][i][l] + f[y][j][l];
					if(l < dfn[y] || l > dfn[y] + sz[y] - 1)
						if(tmp[i+j][l] > f[x][i][l] + mn) tmp[i+j][l] = f[x][i][l] + mn;
				}
			}
		for(int i = 0;i <= min(siz[x] + siz[y],tot);i++)
			for(int j = 1;j <= n;j++)
				f[x][i][j] = tmp[i][j];
		siz[x] += siz[y];
	}
}

signed main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,ld = in;tot = 0;
	for(int i = 1;i <= n;i++) col[i] = in,tot += col[i];
	for(int i = 1;i < n;i++){
		int u = in,v = in,w = in;
		G[u].pb(pii(v,w)); G[v].pb(pii(u,w));
	}
	for(int i = 1;i <= n;i++)
		for(int j = 0;j <= n;j++)
			for(int k = 1;k <= n;k++)
				f[i][j][k] = n + 1;
	for(int i = 1;i <= n;i++) dfs2(dis[i],i,0);
	dfs1(1,0);
	dp(1,0);
	short ans = n + 1;
	for(int i = 1;i <= n;i++) ans = min(ans,f[1][tot][i]);
	if(ans == n + 1) puts("-1");
	else printf("%d\n",ans);
	return 0;
}

